package com.TIEmulator;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.Spanned;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.TIEmulator.FileIOLib.FileBrowser;
import com.TIEmulator.FileIOLib.FileBrowser.Interface;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

public class TIEmuBrowser extends MyAct
  implements FileBrowser.Interface
{
  public static final String BROWSER_PATH_SELECTED_ID = "1";
  private static final int DIALOG_CREATE_DIRECTORY = 1;
  private static final int DIALOG_DIRECTORY_SELECTED = 2;
  private static final int DIALOG_FILE_SELECTED = 3;
  private static final int INPUT_ID = 512;
  private static final int RC_CANCEL = -1;
  private static final int RC_SUCCESS = 0;
  public static final String START_BROWSER_PATH_ID = "0";
  private static final int SUB_ACTIVITY_DOWNMAN_REQUEST_CODE;
  private static FileBrowser filebrowser = null;
  private ListView browser_lv = null;
  private TextView mCreateDirView;
  private String selected_dir = null;
  private TIEmulatorSettings tiemu_setup;
  private TextView top_bar = null;

  public void OnDirSelectedCb()
  {
    showDialog(2);
  }

  public void OnFileSelectedCb(String paramString)
  {
    showDialog(3);
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if (paramInt1 == 0)
      filebrowser.Update();
    while (true)
    {
      return;
      super.onActivityResult(paramInt1, paramInt2, paramIntent);
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
    case 2131296264:
    case 2131296260:
    case 2131296261:
    case 2131296262:
    case 2131296258:
    case 2131296259:
    case 2131296263:
    }
    while (true)
    {
      return;
      setResult(-1, null);
      finish();
      continue;
      showDialog(1);
      continue;
      filebrowser.ZoomIn();
      continue;
      filebrowser.ZoomOut();
      continue;
      filebrowser.upOneLevel();
      filebrowser.Update();
      continue;
      Intent localIntent = new Intent(this, DownloadManager.class);
      this.tiemu_setup.setCurrDir(filebrowser.getDirectorySelected() + "/");
      startActivityForResult(localIntent, 0);
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.tiemu_setup = new TIEmulatorSettings(this);
    LinearLayout localLinearLayout = (LinearLayout)View.inflate(this, 2130903040, null);
    setContentView(localLinearLayout);
    this.top_bar = ((TextView)findViewById(2131296256));
    this.browser_lv = ((ListView)findViewById(2131296265));
    Iterator localIterator = localLinearLayout.findViewById(2131296257).getTouchables().iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
        return;
      ((View)localIterator.next()).setOnClickListener(this);
    }
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    AlertDialog localAlertDialog;
    switch (paramInt)
    {
    default:
    case 1:
      label30: EditText localEditText;
      String str2;
      for (localAlertDialog = null; ; localAlertDialog = new AlertDialog.Builder(this).setTitle(2131165189).setIcon(17301547).setMessage(str2).setView(localEditText).setPositiveButton(17039370, new DialogInterface.OnClickListener(localEditText)
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          File localFile = new File(TIEmuBrowser.filebrowser.getDirectorySelected() + "/" + this.val$input.getText().toString());
          localFile.mkdir();
          TIEmuBrowser.filebrowser.browseTo(localFile);
        }
      }).setNegativeButton(17039360, null).create())
      {
        int i;
        while (true)
        {
          return localAlertDialog;
          localEditText = new EditText(this);
          i = 255 - filebrowser.getDirectoryLength();
          if (i != 0)
            break;
          String str3 = getString(2131165219);
          localAlertDialog = new AlertDialog.Builder(this).setTitle(2131165220).setIcon(17301543).setMessage(str3).setNegativeButton(17039360, null).create();
        }
        InputFilter[] arrayOfInputFilter = new InputFilter[2];
        arrayOfInputFilter[0] = new InputFilter.LengthFilter(i);
        arrayOfInputFilter[1] = new FileNameInputFilter(null);
        localEditText.setFilters(arrayOfInputFilter);
        localEditText.setSingleLine();
        localEditText.setId(512);
        str2 = getString(2131165190);
      }
    case 2:
    case 3:
    }
    this.mCreateDirView = new TextView(this);
    if (paramInt == 3);
    for (String str1 = getString(2131165222); ; str1 = getString(2131165221))
    {
      localAlertDialog = new AlertDialog.Builder(this).setTitle(str1).setIcon(17301659).setView(this.mCreateDirView).setPositiveButton(17039379, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          Intent localIntent = new Intent(TIEmuBrowser.this, TIEmuStartup.class);
          localIntent.putExtra("1", TIEmuBrowser.this.selected_dir);
          TIEmuBrowser.this.setResult(0, localIntent);
          TIEmuBrowser.this.finish();
        }
      }).setNegativeButton(17039369, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          TIEmuBrowser.filebrowser.upOneLevel();
        }
      }).create();
      break label30:
    }
  }

  public void onPause()
  {
    SharedPreferences.Editor localEditor = getPreferences(0).edit();
    localEditor.putString("curr_dir", filebrowser.getDirectorySelected());
    localEditor.putFloat("browser_zoom", filebrowser.getZoom());
    localEditor.commit();
    super.onPause();
  }

  protected void onPrepareDialog(int paramInt, Dialog paramDialog)
  {
    switch (paramInt)
    {
    default:
      label24: super.onPrepareDialog(paramInt, paramDialog);
      return;
    case 2:
    case 3:
    }
    this.selected_dir = filebrowser.getDirectorySelected();
    if (paramInt == 3);
    for (String str1 = getString(2131165223); ; str1 = getString(2131165227))
    {
      String str2 = str1 + "<" + this.selected_dir + ">";
      this.mCreateDirView.setText(str2);
      break label24:
    }
  }

  public void onResume()
  {
    super.onResume();
    SharedPreferences localSharedPreferences = getPreferences(0);
    String str = localSharedPreferences.getString("curr_dir", getIntent().getExtras().getString("0"));
    filebrowser = new FileBrowser(this, this.browser_lv, this.top_bar, str);
    filebrowser.setZoom(localSharedPreferences.getFloat("browser_zoom", 20.0F));
    View localView = findViewById(2131296263);
    localView.setClickable(this.tiemu_setup.getPossesTI());
    localView.setOnClickListener(this);
  }

  private static class FileNameInputFilter
    implements InputFilter
  {
    public CharSequence filter(CharSequence paramCharSequence, int paramInt1, int paramInt2, Spanned paramSpanned, int paramInt3, int paramInt4)
    {
      int i = 0;
      int j = 0;
      if (j >= paramInt2)
      {
        label6: if (i == 0)
          break label86;
        if (j <= 0)
          break label79;
      }
      label79: label86: for (Object localObject = paramCharSequence.subSequence(0, j - 1); ; localObject = paramCharSequence)
        while (true)
        {
          return localObject;
          if (!(paramCharSequence.charAt(j).matches("\\w")))
            i = 1;
          ++j;
          break label6:
          localObject = "";
        }
    }
  }
}
